package utils

import (
	"errors"
	"go-malphite/app/common/panics"
	"go-malphite/app/common/state"
	"gorm.io/gorm"
)

func CheckErr(err error) {
	if err != nil {
		panic(err)
	}
}

func CheckBindParamErr(err error) {
	if err != nil {
		panics.Error(state.ParamsBind, err)
	}
}

func CheckDBErr(err error) {
	if err != nil {
		if !errors.Is(err, gorm.ErrRecordNotFound) {
			panics.Error(state.DB, err)
		}
	}
}

func CheckCopyErr(err error) {
	if err != nil {
		panics.Error(state.CopyStruct, err)
	}
}

func CheckDBErrSyn(err error) {
	if err != nil {
		if !errors.Is(err, gorm.ErrRecordNotFound) {
			panics.Error(state.DB, err)
		}
	}
}

func CheckCopyErrSyn(err error) {
	if err != nil {
		panics.Error(state.CopyStruct, err)
	}
}
